package com.jwdf.uda.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.jwdf.uda.R;
import com.jwdf.uda.utils.DisplayUtils;

/**
 * 类说明：弹出框
 */
public abstract class BaseDialog extends Dialog{
    protected abstract View onInflateView(LayoutInflater inflater);
    protected abstract void onInitView(View view);

    public BaseDialog(Context context) {
        super(context, R.style.transparent_dialog_style);
    }
    public BaseDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = onInflateView(inflater);
        onInitView(view);
        setContentView(view);
    }

    @Override
    public void show() {
        super.show();
        //设置大小
        WindowManager.LayoutParams lp = this.getWindow().getAttributes();

        lp.width = (int) (DisplayUtils.getDeviceWidth(getContext()) - getContext().getResources().getDimension(R.dimen.dialog_frame_interval_width));
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        this.getWindow().setAttributes(lp);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        dismiss();
    }
}
